<template>
	<view class="cardItem">
		<view class="cardItem_top">
			<view class="cardItem_top_left">
				<view class="cardItem_top_left_line">

				</view>
				<view class="cardItem_top_left_title color3" v-if='orderObj.orderType == 1'>
					机构申请
				</view>
				<view class="cardItem_top_left_title" v-else
					:class="orderObj.ningboOrderType == 3?'color2':orderObj.ningboOrderType == 2?'color1':'color0'">
					{{ningboOrderTypeMap[orderObj.ningboOrderType]}}
				</view>
			</view>
			<view class="cardItem_top_right">
				<view class="cardItem_top_right_btn" :style='colorordersStatusType(Number(orderObj.ordersStatus))'>
					{{ordersStatusMap[orderObj.ordersStatus]}}
				</view>
				<view class="cardItem_top_right_btn" :style='colorType(Number(orderObj.serviceStatus))'>
					{{serviceStatusMap[orderObj.serviceStatus]}}
				</view>

			</view>
		</view>
		<view class="cardItem_top">
			<view class="cardItem_price" v-if="orderObj.amount">
				已支付<text class='redPrice'>{{orderObj.amount}}</text>元
			</view>
			<view v-else></view>
			<view v-if="orderObj.uploadAllStatus||orderObj.uploadAllStatus===0" class="cardItem_top_right_btn flexEnd"
				:style='addColorType(Number(orderObj.uploadAllStatus ))'>
				{{uploadAllStatusMap[orderObj.uploadAllStatus ]}}
			</view>
		</view>
		<view class="orderItemSteps">
			<view class="" v-if="orderObj.ningboOrderType == 2">
				<u-steps :current="orderObj.serviceStatus == 2 ? 3 : 1">
					<u-steps-item title="申请"></u-steps-item>
					<u-steps-item title="检测中"></u-steps-item>
					<u-steps-item title="已完成"></u-steps-item>
				</u-steps>
			</view>
			<view class="" v-else>
				<view class="" v-if="getStepStatus(orderObj.ordersStatus,orderObj.serviceStatus)==1">
					<u-steps :current="getStepsValue(orderObj.ordersStatus,orderObj.serviceStatus)">
						<u-steps-item title="申请"></u-steps-item>
						<u-steps-item title="整理分配"></u-steps-item>
						<u-steps-item title="诊断中"></u-steps-item>
						<u-steps-item title="初诊结束"></u-steps-item>
						<u-steps-item title="加做支付"></u-steps-item>
						<u-steps-item title="加做诊断中"></u-steps-item>
						<u-steps-item title="诊断结束"></u-steps-item>
					</u-steps>
				</view>
				<view class="" v-else>
					<u-steps :current="getStepsValue(orderObj.ordersStatus,orderObj.serviceStatus)">
						<u-steps-item title="申请"></u-steps-item>
						<u-steps-item title="整理分配"></u-steps-item>
						<u-steps-item title="诊断中"></u-steps-item>
						<u-steps-item title="诊断结束"></u-steps-item>
					</u-steps>
				</view>
			</view>
		</view>

		<view class="cardItem_infosContaines">
			<view class="cardItem_infosContaines_content">
				<view class="cardItem_infosContaines_content_item">
					<view class="cardItem_infosContaines_content_item_label ">
						申请日期
					</view>
					<view class="cardItem_infosContaines_content_item_title">
						{{orderObj.createTime}}
					</view>
				</view>
				<view class="cardItem_infosContaines_content_item">
					<view class="cardItem_infosContaines_content_item_label ">
						订单ID
					</view>
					<view class="cardItem_infosContaines_content_item_title">
						{{orderObj.id}}
					</view>
				</view>
				<view class="cardItem_infosContaines_content_item">
					<view class="cardItem_infosContaines_content_item_label ">
						订单号
					</view>
					<view class="cardItem_infosContaines_content_item_title">
						{{orderObj.orderNumber}}
					</view>
				</view>
				<view class="cardItem_infosContaines_content_item" v-if="orderObj.typeOfConsultationName">
					<view class="cardItem_infosContaines_content_item_label ">
						会诊类别
					</view>
					<view class="cardItem_infosContaines_content_item_title">
						{{orderObj.typeOfConsultationName}}
					</view>
				</view>
				<view class="cardItem_infosContaines_content_item" v-if="orderObj&&orderObj.patients">
					<view class="cardItem_infosContaines_content_item_label ">
						患者信息
					</view>
					<view class="cardItem_infosContaines_content_item_title_infos">
						<view class="cardItem_infosContaines_content_item_title_infos_name">
							{{orderObj.patients[0].name}}
						</view>
						<view class="cardItem_infosContaines_content_item_title_infos_line"
							v-if="orderObj.patients[0].sexName">

						</view>
						<view class="cardItem_infosContaines_content_item_title_infos_name"
							v-if="orderObj.patients[0].sexName">
							{{orderObj.patients[0].sexName}}
						</view>
						<view class="cardItem_infosContaines_content_item_title_infos_line"
							v-if="orderObj.patients[0].age">

						</view>
						<view class="cardItem_infosContaines_content_item_title_infos_name"
							v-if="orderObj.patients[0].age">
							{{orderObj.patients[0].age}}
						</view>
						<view class="cardItem_infosContaines_content_item_title_infos_line"
							v-if="orderObj.patients[0].cellphone">

						</view>
						<view class="cardItem_infosContaines_content_item_title_infos_name"
							v-if="orderObj.patients[0].cellphone">
							{{orderObj.patients[0].cellphone}}
						</view>
					</view>
				</view>
				<view class="cardItem_infosContaines_content_item" v-if="orderObj.orderType==1">
					<view class="cardItem_infosContaines_content_item_label ">
						送检信息
					</view>
					<view class="cardItem_infosContaines_content_item_title_infos">
						<view class="cardItem_infosContaines_content_item_title_infos_name">
							{{orderObj.sendingHospitalName}}
						</view>
						<view class="cardItem_infosContaines_content_item_title_infos_line"
							v-if="orderObj.sendingDoctor">

						</view>
						<view class="cardItem_infosContaines_content_item_title_infos_name"
							v-if="orderObj.sendingDoctor">
							{{orderObj.sendingDoctor}}
						</view>
					</view>
				</view>
				<view class="cardItem_infosContaines_content_item" v-else>
					<view class="cardItem_infosContaines_content_item_label ">
						送检信息
					</view>
					<view class="cardItem_infosContaines_content_item_title_infos">
						<view class="cardItem_infosContaines_content_item_title_infos_name">
							个人申请
						</view>
					</view>
				</view>
				<view class="cardItem_infosContaines_content_item">
					<view class="cardItem_infosContaines_content_item_label ">
						取材部位
					</view>
					<view class="cardItem_infosContaines_content_item_title_infos">
						<view class="cardItem_infosContaines_content_item_title_infos_name">
							{{orderObj.patients[0].diagnosisHistory[0].visceraName}}
						</view>
						<view class="cardItem_infosContaines_content_item_title_infos_line"
							v-if="orderObj.patients[0].diagnosisHistory[0].visceraName&&orderObj.patients[0].diagnosisHistory[0].diseaseLocation">

						</view>
						<view class="cardItem_infosContaines_content_item_title_infos_name"
							v-if="orderObj.patients[0].diagnosisHistory[0].diseaseLocation">
							{{orderObj.patients[0].diagnosisHistory[0].diseaseLocation}}
						</view>
					</view>
				</view>
				<view class="cardItem_infosContaines_content_item">
					<view class="cardItem_infosContaines_content_item_label ">
						会诊信息
					</view>
					<view class="cardItem_infosContaines_content_item_title_infos">
						<view class="cardItem_infosContaines_content_item_title_infos_name">
							{{orderObj.serviceCenterName}}
						</view>
						<view class="cardItem_infosContaines_content_item_title_infos_line"
							v-if="getexpertName(orderObj)">

						</view>
						<view class="cardItem_infosContaines_content_item_title_infos_name"
							v-if="getexpertName(orderObj)">
							{{getexpertName(orderObj)}}
						</view>
					</view>
				</view>

				<template
					v-if="(orderObj.ordersStatus == 1 || orderObj.ordersStatus == 4 || orderObj.ordersStatus == 10 || orderObj.ordersStatus == 12) && orderObj.serviceStatus == 2">
				</template>
				<template v-else>
					<view v-if="orderObj.timeout || orderObj.remainder" class="cardItem_infosContaines_content_item">
						<view class="cardItem_infosContaines_content_item_label ">
							会诊倒计时
						</view>
						<view v-if="orderObj.remainder && orderObj.remainder > 0"
							class="cardItem_infosContaines_content_item_title">
							<Countdown :end-time="getdeadline(orderObj.remainder)" type="perOrder"></Countdown>
						</view>
						<view v-if="orderObj.timeout && orderObj.timeout > 0"
							class="cardItem_infosContaines_content_item_title">
							<timeoutCountdown :star-time="getStartline(orderObj.timeout)" type="perOrder">
							</timeoutCountdown>
						</view>
					</view>
				</template>

			</view>
		</view>
		<view class="cardItem_bottom">
			<view class="cardItem_bottom_btnGroup">
				<view class="cardItem_bottom_btnGroup_item" v-for="(item, index) in btnGroupArr" :key="index">
					<block v-if="item.label == '快递'">
						<view class="cardItem_bottom_btnGroup_item_btn"
							:style="{color:getColorFromRow(orderObj,item),borderColor:getColorFromRow(orderObj, item)}"
							@tap="clickButton(item.functionKey, orderObj)">
							{{item.label}} <text
								v-if="orderObj.expressCount">({{orderObj.receiveWithoutSignInCount }}/{{orderObj.expressCount }})</text>
						</view>
					</block>
					<block v-else-if="item.label == '服务提醒'">
						<view class="cardItem_bottom_btnGroup_item_btn"
							:style="{ color:orderObj.unprocessedMessagesNumber ? 'red' : '#266EFF',borderColor:orderObj.unprocessedMessagesNumber ? 'red' : '#266EFF' }"
							@tap="clickButton(item.functionKey, orderObj)">
							{{item.label}} <text
								v-if="orderObj.unprocessedMessagesNumber">({{ orderObj.unprocessedMessagesNumber }})</text>
						</view>
					</block>
					<block v-else-if="item.label == '确认退款'">
						<view class="cardItem_bottom_btnGroup_item_btn" style="color:red;borderColor:red"
							@tap="clickButton(item.functionKey, orderObj)">
							{{item.label}}
						</view>
					</block>
					<block v-else-if="item.label == '切片'">
						<view class="cardItem_bottom_btnGroup_item_btn"
							:style="{ color: orderObj.slicesNumber ? '#e408f7' : '#999',borderColor: orderObj.slicesNumber ? '#e408f7' : '#999'}"
							@tap="clickButton(item.functionKey, orderObj)">
							{{item.label}}
							<text v-if="orderObj.slicesNumber">({{ orderObj.slicesNumber }})</text>
						</view>
					</block>
					<block v-else-if="item.label == '沟通'">
						<view class="cardItem_bottom_btnGroup_item_btn"
							:style="{ color: orderObj.unReadMessageNumber ? 'red' : '#266EFF',borderColor: orderObj.unReadMessageNumber ? 'red' : '#266EFF'}"
							@tap="clickButton(item.functionKey, orderObj)">
							{{item.label}}
							<text v-if="orderObj.unReadMessageNumber">({{ orderObj.unReadMessageNumber }})</text>
						</view>
					</block>

					<block v-else>
						<view class="cardItem_bottom_btnGroup_item_btn" @tap="clickButton(item.functionKey, orderObj)">
							{{item.label}}
						</view>
					</block>

				</view>

			</view>
		</view>
	</view>

</template>

<script>
	import {
		mapState
	} from 'vuex'
	import Countdown from '@/components/Countdown/Countdown.vue'
	import timeoutCountdown from '@/components/timeoutCountdown/timeoutCountdown.vue'
	import {
		serviceStatusMap,
		ningboOrderTypeMap,
		ordersStatusMap,
		uploadAllStatusMap
	} from '@/utils/baseData.js'
	export default {
		name: "orderItem",
		props: ['orderObj', 'title', 'itemIndex', 'btnGroupArr'], //entranceType  1:专家介绍进入 2:特需会诊进入
		components: {
			Countdown,
			timeoutCountdown
		},
		computed: {
			...mapState({
				userId: state => state.user.userInfo.id, 
			}),
		},
		data() {
			return {
				serviceStatusMap: serviceStatusMap,
				ningboOrderTypeMap: ningboOrderTypeMap,
				ordersStatusMap: ordersStatusMap,
				uploadAllStatusMap: uploadAllStatusMap
			}
		},
		created() {

		},
		methods: {
			getStepStatus(orderStatus, serviceStatus) {
				if (orderStatus == 3 || orderStatus == 4) {
					return 1
				} else {
					return 2
				}

			},
			getStepsValue(orderStatus, serviceStatus) {
				//
				if (serviceStatus == 5 || serviceStatus == 0) { //未整理 
					return 1
				} else if (serviceStatus == 1) {
					return 2
				} else if (serviceStatus == 2 && orderStatus != 3 && orderStatus != 4) {
					return 3
				} else if (orderStatus == 3) {
					return 4
				} else if (orderStatus == 4) {
					return 5
				} else if (serviceStatus == 2 && orderStatus == 4) {
					return 6
				}
			},
			getdeadline(value) {
				// 获取当前时间
				var now = new Date();
				// 当前时间加上200000秒
				now.setSeconds(now.getSeconds() + value);
				// 输出结果
				return now
			},
			getStartline(value) {
				// 获取开始时间
				var now = new Date();
				// 当前时间加上200000秒
				now.setSeconds(now.getSeconds() - value);
				// 输出结果
				return now
			},
			getColorFromRow(row, item) {
				// console.log('getColorFromRow--row',row)
				// console.log('getColorFromRow',item)
				if (row && row.receiveWithoutSignInCount > 0 && item.label == '快递') {
					return 'red'
				} else if (row && row.receiveWithoutSignInCount == null && item.label == '快递') { //
					return '#999999'
				} else {
					return '#266EFF'
				}

			},
			// 按钮点击
			clickButton(functionKey, row, item) {
				// return
				if (item && item.viewOrderId == row.id) {
					// this.$message.warning('当前浏览的')
					return false
				}
				this.$emit('handleClick', functionKey, row)
			},
			getexpertName(item) {
				if (item && item.patients[0]) {
					if (item.patients[0].expertDiagnosis && item.patients[0].expertDiagnosis[0]) {
						return item.patients[0].expertDiagnosis[0].expertName
					} else {
						return ''
					}
				} else {
					return ''
				}
			},
			colorordersStatusType(item) {
				switch (item) {
					//    
					case 1:
					case 4:
						return {
							'background-color': '#fdf6ec', 'border-color': '#00BF5B', color: '#00BF5B'
						} //success
					case 3:
						return {
							'background-color': '#fdf6ec', 'border-color': '#fde2e2', color: '#FF4646'
						} //danger
					case 6:
						return {
							'background-color': '#fdf6ec', 'border-color': '#faecd8', color: '#266EFF'
						} //'warning'
					case 7:
					case 8:
					case 9:
					case 11:
					case 10:
						return {
							'background-color': '#fdf6ec', 'border-color': '#faecd8', color: '#266EFF'
						} //'warning'
					default:
						return {
							'background-color': '#fdf6ec', 'border-color': '#f4f4f5', color: '#999999'
						} //info
				}
			},
			colorType(item) {
				switch (item) {
					case 0:
						return {
							'background-color': '#00BF5B', 'border-color': '#e1f3d8', color: '#FFFFFF'
						} //success
					case 1:
						return {
							'background-color': '#FF4646', 'border-color': '#fde2e2', color: '#FFFFFF'
						} //danger
					case 2:
						return {
							'background-color': '#00BF5B', 'border-color': '#e1f3d8', color: '#FFFFFF'
						} //success
					case 3:
						return {
							'background-color': '#f4f4f5', 'border-color': '#e9e9eb', color: '#266EFF'
						} //info
					case 4:
						return {
							'background-color': '#f4f4f5', 'border-color': '#e9e9eb', color: '#266EFF'
						} //info
					case 5:
						return {
							'background-color': '#FF4646', 'border-color': '#fde2e2', color: '#FFFFFF'
						} //danger
					case 6:
						return {
							'background-color': '#fdf6ec', 'border-color': '#faecd8', color: '#266EFF'
						} //'warning'
					default:
						return {
							'background-color': '#00BF5B', 'border-color': '#e1f3d8', color: '#FFFFFF'
						} //success
				}
			},
			addColorType(item) {
				switch (item) {
					case 0:
						return {
							'background-color': '#fdf6ec', 'border-color': '#fde2e2', color: '#FF4646'
						} //danger
					case 1:
						return {
							'background-color': '#fdf6ec', 'border-color': '#00BF5B', color: '#00BF5B'
						} //success
					case 2:
						return {
							'background-color': '#fdf6ec', 'border-color': '#faecd8', color: '#e6a23c'
						} //danger
					default:
						return {
							'background-color': '#f0f9eb', 'border-color': '#e1f3d8', color: '##67c23a'
						} //success
				}
			}

		}
	}
</script>

<style lang="scss" scoped>
	.orderItemSteps {
		padding-top: 6px;

		::v-deep .u-steps-item {
			.u-text__value {
				font-size: 20rpx !important;
			}

		}
	}

	.redPrice {
		font-size: 28rpx;
		margin: 0 4rpx;
		color: red;
	}

	.color0 {
		background: linear-gradient(180deg, #5DDFFA 0%, #1E68E3 100%);
		color: #ffffff;
		background-clip: text;
		font-weight: 700;
		-webkit-background-clip: text;
		-webkit-text-fill-color: transparent;
		display: inline-block;
	}

	.color1 {
		background: linear-gradient(180deg, #4CE4D5 0%, #0FB6D2 100%);
		color: #ffffff;
		background-clip: text;
		font-weight: 700;
		-webkit-background-clip: text;
		-webkit-text-fill-color: transparent;
		display: inline-block;

	}

	.color2 {
		background: linear-gradient(180deg, #74ADFE 0%, #7E61EF 99%);
		color: #ffffff;
		font-weight: 700;
		background-clip: text;
		-webkit-background-clip: text;
		-webkit-text-fill-color: transparent;
		display: inline-block;

	}

	.color3 {
		background: linear-gradient(180deg, #4CE4D5 0%, #0FB6D2 100%);
		color: #ffffff;
		background-clip: text;
		font-weight: 700;
		-webkit-background-clip: text;
		-webkit-text-fill-color: transparent;
		display: inline-block;
	}

	.cardItem.first {
		margin-top: 0rpx;
	}

	.cardItem {
		position: relative;
		margin: 0 10rpx;
		padding: 16rpx 12rpx;
		box-shadow: 2rpx 2rpx 8rpx 8rpx rgba(32, 108, 228, 0.3);
		border-radius: 8rpx;
		margin-top: 48rpx;
		color: rgba(51, 51, 51, 1);

		&_top {
			display: flex;
			align-items: center;
			justify-content: space-between;
			line-height: 56rpx;

			&_left {
				display: flex;
				align-items: center;

				&_line {
					width: 6rpx;
					height: 32rpx;
					background: rgba(42, 139, 239, 1);
					border-radius: 4rpx;
					margin-right: 8rpx;
				}

				&_title {
					color: rgba(51, 51, 51, 1);
					font-size: 28rpx;
					font-weight: 600;
				}
			}

			&_right {
				display: flex;
				align-items: center;

				&_btn {
					padding: 0 6rpx;
					border-radius: 6rpx;
					margin-right: 8rpx;
					line-height: 40rpx;
					font-size: 26rpx;
					transform: scale(0.9);
					border: 2rpx solid #fff;
				}

				&_btn:last-child {
					margin: 0rpx;
				}

			}
		}

		&_price {
			color: rgba(42, 139, 239, 1);
			font-size: 28rpx;
			line-height: 40rpx;
			padding-left: 12rpx;
		}

		&_infosContaines {
			padding: 20rpx 12rpx;
			font-size: 26rpx;

			&_content {
				border-top: 2rpx solid rgba(197, 197, 197, 1);
				padding-top: 20rpx;

				&_item:first-child {
					margin-top: 0rpx;
				}

				&_item {
					margin-top: 10rpx;
					display: flex;
					font-size: 26rpx;
					line-height: 40rpx;

					&_label {
						color: #666666;
						width: 140rpx;
						margin-right: 12rpx;
					}

					&_title {
						color: #111111;

						&_infos {
							display: flex;
							flex-wrap: wrap;
							align-items: center;

							&_name {
								font-weight: 700;
							}

							&_line {
								width: 2rpx;
								height: 20rpx;
								background: rgba(168, 168, 168, 1);
								margin: 0 10rpx;
							}
						}
					}
				}
			}

		}

		&_bottom {
			&_btnGroup {
				display: flex;
				align-items: center;
				flex-wrap: wrap;

				&_item {
					padding: 10rpx;

					&_btn {
						cursor: pointer;
						padding: 2rpx 16rpx;
						height: 48rpx;
						font-size: 26rpx;
						line-height: 42rpx;
						border: 2rpx solid #266EFF;
						border-radius: 6rpx;
						color: #266EFF;
					}
				}
			}
		}
	}
</style>